//图片过于大防止出现横向滚定条;
$(document).ready(function () {
    $("body").attr("style", "overflow-x:hidden");
});
//点击账号密码和短信登录的切换;
// $("PWD").click(function () {
//     $(zhanghao).style.display = "block"
// })

let oPWD = document.querySelector(".PWD");
let ozhanghao = document.querySelector(".zhanghao")
oPWD.onclick = function () {
    ozhanghao.style.display = "none";
}


let oUserName = document.querySelector("#username");
console.log(oUserName);
let oUserPass = document.querySelector("#userpass");
console.log(oUserPass);
let oBtnLogin = document.querySelector(".sing_in");

//点击登录判断
oBtnLogin.onclick = function () {
    console.log(1);
    // 创建xhr对象
    let xhr = new XMLHttpRequest();
    //发送open请求三要素
    xhr.open("post", "goodsAndShoppingCart/login.php", true);
    //因为是post，所以要添加请求头
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    // 发送send请求里面写数据
    let str = "username=" + oUserName.value + "&userpass=" + oUserPass.value;
    xhr.send(str);
    //接受响应
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            // 响应成功
            if (xhr.responseText.trim() == "success") {
                document.querySelector(".msg").innerHTML = "登录成功";
                //定时器两秒跳转箭头函数写法
                setInterval(() => {
                    location.href = "http://localhost/2209/Anta/index.html";
                }, 2000);
            } else {
                // 响应失败
                document.querySelector(".msg").innerHTML = "登录失败,用户名或者密码错误";
            }
        }
    }
}
